<?php 
header("content-type:text/html;charset=utf-8");
$pdo = new PDO("mysql:host=127.0.0.1;dbname=ww01","root","root");
$city = $_POST['city'];
$ssql = "select * from wea where city = '$city' ";
// print_r($ssql);die();
$res = $pdo->query($ssql)->fetchAll(PDO::FETCH_ASSOC);
if (!$res) {
	$url = "http://www.wea.com/ser.php?city=$city";
	$data = file_get_contents($url);
	$data = json_decode($data,true);

	$res = $data['result'];
	// print_r($res);
	foreach ($res as $value) {
		$week = $value['week'];
		$city = $value['citynm'];
		$temp_high = $value['temp_high'];
		$temp_low = $value['temp_low'];
		$temperature = $value['temperature'];
		$sql = "insert into wea values('','$city','$week','$temp_high','$temp_low','temperature')";
		$pdo->exec($sql);
	}
}
echo json_encode($res);
 ?>